const mysql = require('mysql')
let utils = {
    query(sql,arr,fun){
        const conn = mysql.createConnection({
            host:'localhost',
            port:3306,
            user:'root',
            password:'root',
            database:'shop'
        })
        conn.connect()
        conn.query(sql,arr,fun)
        conn.end()
    },
    getBanner(){
        return new Promise((resolve, reject) => {
            utils.query("select * from banner where keyName='lun'",[],function (err,data) {
                resolve(data)
            })
        })

    },
    getNewList(){
        return new Promise((resolve, reject) => {
            let sql2 =`SELECT product.*,productrule.Id AS rid FROM product JOIN productrule ON product.Id = productrule.productId WHERE isDefault =1 
AND isNew=1`;
            utils.query(sql2,[],function (err,data) {
                resolve(data)
            })
        })
    }
}
module.exports = utils